#include "namespc.h"
#include <iostream>
namespace pers {

    void getPerson(Person & aPerson)
        {
        using namespace std;
        cout << "Input first name please:" << endl;
        // 使用cin方法没有忽略第一个的问题，使用getline会有忽略第一个getline的问题，
        // 因为它使用残余在cin缓冲区中的enter字符
        // cin >> aPerson.fname;
        getline(cin >> ws, aPerson.fname);
        cout << "Input last name please:" << endl;
        // cin >> aPerson.lname;
        // 注意这里的 >> ws，它将cin中的垃圾给吸收了：
        // 参考：https://www.geeksforgeeks.org/problem-with-getline-after-cin/#:~:text=The%20getline()%20function%20does,in%20the%20stream%20as%20garbage.
        //      https://www.geeksforgeeks.org/manipulators-in-c-with-examples/
        getline(cin >> ws, aPerson.lname);
    }

    void showPerson(Person &aPerson)
    {
        using namespace std;
        cout << "First name: " << aPerson.fname << endl;
        cout << "Last name: " << aPerson.lname << endl;
    }

}

namespace debts {

    void getDebt(Debt &aDebt) {
        pers::getPerson(aDebt.person);
        using namespace std;
        cout << "Please input the amount of debts: " << endl;
        cin >> aDebt.amount;
    }

    void showDebt(Debt & aDebt) {
        pers::showPerson(aDebt.person);
        using namespace std;
        cout << "amount: " << aDebt.amount << endl;
    }

    double totalDebt(const Debt array[], int num) {
        double sumNum = 0.0;
        for (int i = 0; i < num; i++)
        {
            sumNum += array[i].amount;
        }
        return sumNum;
    }
}
